package com.lp.websocket;

import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;
import org.springframework.web.socket.handler.TextWebSocketHandler;

import java.util.HashMap;
import java.util.Map;



/**
// *
 * websocket 数据接收与分发
 *
 *
 */
public class WebsocketEndPoint extends TextWebSocketHandler {


	private static Map<String, WebSocketSession> userIdSession = new HashMap<String, WebSocketSession>();

	@Override
	protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
		super.handleTextMessage(session, message);
		TextMessage returnMessage = new TextMessage(message.getPayload());
		// 到session里面找到to_user_id的绘画
		String msg = returnMessage.toString();

	}

	/**
	 * 获取userId
	 *
	 * @param session
	 * @return
	 */
	public static Integer getUserId(WebSocketSession session) {
		return (Integer) session.getHandshakeAttributes().get("user_id");
	}

	/**
	 * 获取USER-KEY
	 *
	 * @param session
	 * @return
	 */
	public static String getUserKey(WebSocketSession session) {
//		return session.getHandshakeHeaders().getFirst(KEY.USER_KEY_ID);
		return null ;
	}

}
